import jsonp from 'assets/js/jsonp'
import { commonParams } from './config'

// 获取MV榜单列表
export function getMvLists(area_type) {
	
	const r = '-=getUCGI' + (Math.random() + '').replace('0.', '')

	const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?' + r
	
	const data = Object.assign({}, commonParams, {
		format: 'json',
		loginUin: 0,
		hostUin: 0,
		needNewCode: 0,
		platform: 'yqq.json',
		data:`{"comm":{"ct":24,"cv":0},"request":{"method":"get_video_rank_list","param":{"rank_type":0,"area_type":${area_type || 0},"required":["vid","name","singers","cover_pic","pubdate"]},"module":"video.VideoRankServer"}}`
	})

	return jsonp(url, data, {})
}

// 获取MV播放地址
export function getMvUrl(vid){

	const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?'

	const datas = Object.assign({}, commonParams, {
		loginUin: 0,
		hostUin: 0,
		needNewCode: 0,
		platform: 'yqq',
		data:`{"getMvUrl":{"module":"gosrf.Stream.MvUrlProxy","method":"GetMvUrls","param":{"vids":["${vid}"],"request_typet":10001}}}`
	})

	return jsonp(url, datas, {})
}

// 获取MV的相关信息，及推荐
export function getMvDetail(vid){

	const r = '-=getUCGI' + (Math.random() + '').replace('0.', '')

	const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?' + r

	const datas = Object.assign({}, commonParams, {
		format: 'json',
		loginUin: 0,
		hostUin: 0,
		needNewCode: 0,
		platform: 'yqq.json',
		data:`{"comm":{"ct":24,"cv":4747474},"mvinfo":{"module":"video.VideoDataServer","method":"get_video_info_batch","param":{"vidlist":["${vid}"],"required":["vid","type","sid","cover_pic","duration","singers","video_switch","msg","name","desc","playcnt","pubdate","isfav","gmid"]}},"other":{"module":"video.VideoLogicServer","method":"rec_video_byvid","param":{"vid":"${vid}","required":["vid","type","sid","cover_pic","duration","singers","video_switch","msg","name","desc","playcnt","pubdate","isfav","gmid","uploader_headurl","uploader_nick","uploader_encuin","uploader_uin","uploader_hasfollow","uploader_follower_num"],"support":1}}}`
	})
	
	return jsonp(url, datas, {})
}
